<?php
/**
 * 省市区地址库管理
 */
namespace logic\sys;
class Area{

    /**
     *获取区域列表
     */
    public function getList($param){
        if(!$param['pcode']) $param['pcode'] = 0;
        $result = cache('logic_area_p_'.$param['pcode']);
        if( $result ) return unserialize($result);
        $data = D('Area','sys')->getList($param);
        cache('logic_area_p_'.$param['pcode'],serialize($data),86400);
        return $data;
    }

    /**
     * 获取一个区域信息
     */
    public function getInfo($code){
        if(!$code) logicE('区域不存在');
        return D('Area','sys')->getInfo($code);
    }
    
    /**
     * 获取一个区域信息
     */
    public function getInfoByName($name){
        if(!$name) logicE('区域不存在');
        return D('Area','sys')->getAreaByName($name);
    }
    
    /**
     * 获取完整的地址信息
     */
    public function getFullAddress($provinceid,$cityid = '',$areaid = '',$streetid = ''){
        $result = '';
        if( $provinceid ){
            $areaInfo =  D('Area','sys')->getInfo($provinceid);
            $result = $result.$areaInfo['name'];
        }
        if( $cityid ){
            $provinceInfo =  D('Area','sys')->getInfo($cityid);
            $result = $result.$provinceInfo['name'];
        }
        if( $areaid ){
            $provinceInfo =  D('Area','sys')->getInfo($areaid);
            $result = $result.$provinceInfo['name'];
        }
        if( $streetid ){
            $provinceInfo =  D('Area','sys')->getInfo($streetid);
            $result = $result.$provinceInfo['name'];
        }
        return $result;
    }

    

}